#include <iostream>

using std::cout;
using std::endl;

class Point
{
public://公有的
    Point(int ix = 0, int iy = 0)
    : _ix(ix)
    , _iy(iy)
    {
        cout << "Point(int, = 0, int = 0)" << endl;
    }

    void print() const
    {
        cout << "(" << _ix
             << ", " << _iy
             << ")" << endl;
    }

    int getY() const
    {
        return _iy;
    }

    ~Point()
    {
        cout << "~Point()" << endl;
    }

protected://保护的
    int _ix;
private://私有的
    int _iy;
};

class Point3D 
: private Point
{
public:
    Point3D(int ix = 0, int iy = 0, int iz = 0)
    //对于从基类吸收的数据成员的初始化，需要借助
    //基类的构造函数
    : Point(ix, iy)
    , _iz(iz)
    {
        cout << "Point3D(int = 0, int = 0, int = 0)" << endl;
    }

    void show() const
    {
        print();//private
        cout << "_ix = " << _ix << endl;//private
        /* cout << "_iy = " << _iy << endl;//error */
        cout << "_iy = " << getY() << endl;//ok,private
    }

    ~Point3D()
    {
        cout << "~Point()" << endl;
    }
private:
    int _iz;
};

class Point4D
: private Point3D
{
public:
    void show() const
    {
        /* print();//error */
        /* cout << "_ix = " << _ix << endl;//error */
        /* cout << "_iy = " << _iy << endl;//error */
        /* cout << "_iy = " << getY() << endl;//error */
    }

};

void test()
{
    cout << "sizeof(Point) = " << sizeof(Point) << endl;//8
    cout << "sizeof(Point3D) = " << sizeof(Point3D) << endl;//4 + 8
    Point3D pt3d(1, 2, 3);
    /* pt3d.print();//error */
    /* pt3d.getY();//error */
    /* pt3d._ix;//error */
    /* pt3d._iy;//error */
}

int main(int argc, char *argv[])
{
    test();
    return 0;
}

